package hydrap2p.gui.commands;

import hydrap2p.gui.FileTransferPanel;
import hydrap2p.gui.GUIDataHandler;
import hydrap2p.gui.GUIDownloadListing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.thrift.TException;

public class Cmd_FileTransferPanel_RemoveFromDownloads implements Command {

	@Override
	public void execute() {
		// Remove the indices from the download listing
		Map<Integer, Integer> tableMap = FileTransferPanel.getInstance().getIndexMappings();
		int gdlIndex;
		int selectedRows[] = FileTransferPanel.getInstance().getTable().getSelectedRows();

		for(int j = selectedRows.length - 1; j >= 0; j--)
		{
			int i = selectedRows[j];
			
			// Get the position in the table to be removed
			gdlIndex = tableMap.get(i); 
			GUIDataHandler.getInstance().removeFromDownloadListing(GUIDataHandler.getInstance().getDownloadListing().get(gdlIndex));
		}
		
		// Clear table selections
		FileTransferPanel.getInstance().clearTableSelections();
		
		// Refresh data transfer table
		FileTransferPanel.getInstance().refreshDownloadList();
		
		// Refresh details
		CommandInvoker.getInstance().invokeCommand(new Cmd_DetailsPanel_RefreshDetails());
		
	}

	@Override
	public String getCommand() {
		return this.getClass().getSimpleName();
	}

	@Override
	public void unexecute() {
		// TODO Auto-generated method stub

	}

}
